package com.advanced.commonlyUsedClass_2.packaging;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 输入一行英文句子，句子中只有英文单词和空格，
 * 每个单词之间由若干个空格隔 开，英文单词由大小写字母组成。
 * 统计此句子中单词个数，假定重复出现的单词只计一次，
 * 且 认为大小写字母是相同的，如“The”和“the”是同一个单词。
 *
 * @author: Jovi
 * @createTime: 2017-06-06 16:37
 **/
public class WordAmount {

    public static void main(String[] args) {
        System.out.println("Please enter a line of English sentence");
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        List<String> wordLists = new ArrayList<>();
        String[] strArrays = str.split(" ");
        for (String word : strArrays) {
            word = word.toLowerCase();
            if (!wordLists.contains(word) && !word.equals("")) {
                wordLists.add(word);
            }
        }
        System.out.println("The sentence have " + wordLists.size() + "words");
    }
}
